package org.activiti.camel.exception.tools;

import org.activiti.engine.delegate.BpmnError;
import org.apache.camel.Handler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ThrowBpmnExceptionBean {

    private static final Logger LOG = LoggerFactory.getLogger(ThrowBpmnExceptionBean.class);
    protected static ExceptionType exceptionType;


    public static ExceptionType getExceptionType() {
        return exceptionType;
    }


    public static void setExceptionType(ExceptionType exceptionType) {
        ThrowBpmnExceptionBean.exceptionType = exceptionType;
    }

    @Handler

    public void throwNonBpmnException() throws Exception {
        LOG.debug("throwing non bpmn bug");

        switch (getExceptionType()) {
            case NO_EXCEPTION:
                break;
            case NON_BPMN_EXCEPTION:
                throw new Exception("arbitary non bpmn exception");
            case BPMN_EXCEPTION:
                throw new BpmnError("testError");
        }
    }

    public enum ExceptionType {
        NO_EXCEPTION, BPMN_EXCEPTION, NON_BPMN_EXCEPTION
    }
}
